package xyz.sekai52799.utils;

public class QuickSort {
    public static void quickSort(int[] nums, int start, int end){

        int i,j,temp,t;
        if(start > end){
            return;
        }
        i = start;
        j = end;
        //temp就是基准位
        temp = nums[start];

        while (i < j) {
            //先看右边，依次往左递减
            while (temp <= nums[j] && i < j) {
                j--;
            }
            //再看左边，依次往右递增
            while (temp >= nums[i] && i < j) {
                i++;
            }
            //如果满足条件则交换
            if (i < j) {
                t = nums[j];
                nums[j] = nums[i];
                nums[i] = t;
            }
        }
        //最后将基准为与i和j相等位置的数字交换
        nums[start] = nums[i];
        nums[i] = temp;
        //递归调用左半数组
        quickSort(nums, start, j-1);
        //递归调用右半数组
        quickSort(nums, j+1, end);
    }
}
